[stats_examples.md] Update np.random → Generator API#873
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 tasks
📖 Netlify Preview Ready!Preview URL: https://pr-873--sunny-cactus-210e3e.netlify.app Commit: 📚 Changed LecturesBuild Info
|
Contributor
|
Thanks @Chihiro2000GitHub , this looks good to me. |
thomassargent30
pushed a commit
that referenced
this pull request
May 31, 2026
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
HumphreyYang
added a commit
that referenced
this pull request
Jun 6, 2026
* Tom's May 8 edits of new lecture * Tom's April 9 edits of new and old lectures * Tom's addition of a lecture * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * Update rng usage in lln_clt.md (#874) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix assorted issues in prob_meaning lecture (#878) * Fix typos, spelling, notation errors, and swapped bounds in prob_meaning - Fix spelling: probabilties, probabililty (x6), statististian - Fix doubled word: "to to help" - Fix variance formula: remove erroneous factor of n (rho is Bernoulli, not binomial) - Fix notation: P_{k,i} → rho_{k,i} to match definition - Fix subject-verb agreement: "means converges" → "mean converges" - Fix swapped upper/lower bounds in part (e) ppf calls - Fix compare() to include k=0 - Fix LaTeX: replace * with \cdot for multiplication - Fix log(I) range: text said 2 to 7, code has 2 to 6 - Fix imprecise wording: f_k^I approximates Prob(X=k|θ), not θ - Clarify vague exercise pm_ex1 part 3 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Improve code quality: naming, PEP 8, line length, grid resolution - Rename class frequentist → Frequentist (PEP 8) - Rename Bay_stat → bayes (snake_case for instances) - Rename ii → i/post, num → n_obs, num_list → n_obs_list, kk → k, K → head_counts, comp → table, step_num → n_obs, npt → n_thetas, nn → n_ns, nI → n_Is - Replace (sample <= θ) * 1 with .astype(int) for consistency - Shorten docstrings to fit within 80 characters - Break long code lines (plot calls, list comprehensions, titles) - Increase θ grid from 100 to 1000 points for smoother density plots - Use f-strings with comma formatting for plot labels Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Restructure Bayesian section: derive posterior before exercise - Add back-reference to prob_matrix lecture for Bayes' Law intro - Derive the n-step posterior Beta(α+k, β+n-k) before the exercise, so the exercise solution code no longer precedes its own derivation - Replace the duplicated derivation after the exercise with a concise summary referencing the formula above - Remove duplicate "Now pretend..." sentence before part (c) - Replace "this quantecon lecture" cross-references with actual titles for better PDF rendering Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Replace prettytable with pandas DataFrame in compare() Drop the prettytable dependency — pandas is already imported and renders nicely in Jupyter notebooks. The compare() method now returns a DataFrame instead of printing a PrettyTable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Fix exercise pm_ex2 parts (a) and (b) to match their solutions The question asked for the likelihood of "a sample of length n from a binomial" but the solution gave the single-flip Bernoulli case. Reword both the questions and solution headers so parts (a) and (b) are explicitly about a single coin flip. The general n-step case is already derived in the lecture text before the exercise. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Add reproducible random seeds using modern NumPy API Both classes now accept an rng parameter and use rng.random() instead of np.random.rand(). Each code cell passes a seeded np.random.default_rng() for reproducible output across builds. Also remove "typically" from the hump-shape sentence, since with fixed seeds the behavior is deterministic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Clean up posterior PDF plots - Rename title from "P.D.F" to "PDF" - Simplify legend labels: "n = 0 (prior)", "n = 1", etc. - Remove n = 30, 70, 300, 500 from observation list to reduce clutter in the first PDF plot Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Remove repeated question text from exercise solutions Solutions for parts (c)-(h) no longer duplicate the question text as a header — they just use the part label. This follows the QuantEcon convention. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Use p(θ) for density notation and break up solution derivation - Change P(θ) to p(θ) throughout and note it is a density - Replace the single aligned equation block in the solution for part (b) with three separate display equations, each introduced by explanatory text (Bayes' Law, substitution, collecting powers) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Final review polish: notation, plotting style, consistency - Use **bold** instead of __bold__ for binomial distribution - Use IID instead of i.i.d. - Fix double "with" in exercise (c) wording - Rename quantile variables from p_1/p_2 to q_1/q_2 to avoid clash with p(θ) density notation - Fix "means and variances statistics" → "mean and standard deviation" - Standardize N → n in post-exercise text to match pre-exercise - Update "exceeds 500" → "exceeds 1000" to match revised n_obs_list - Standardize frequentist plots to use ax. methods instead of plt. - Remove dead self.k assignment in Frequentist.binomial() Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Adopt new style guide notation conventions Replace \textrm{Prob}(...) with \mathbb{P}{...} and E[...] with \mathbb{E}[...] following QuantEcon.manual#84. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Update rng usage in stats_examples.md (#873) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> * Tom's May 31 edits of long-run risk lecture * updates * updates * updates * updates * updates * updates * Tom's June 5 edits of long run risk model * update --------- Co-authored-by: thomassargent30 <ts43@nyu.edu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates legacy NumPy random API usage in
stats_examples.mdas part of QuantEcon/meta#299.rng = np.random.default_rng()at the first point of use (Geometric distribution section) and reused it throughout the lecture.np.random.*calls withrng.*equivalents (geometric,negative_binomial,normal,exponential,random).Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.